//
//  FooterTableViewCell.swift
//  Pods
//
//  Created by eme on 2017/3/28.
//
//

import UIKit
import RickonCore

class FooterTableViewCell: UITableViewCell {
    
    @IBOutlet weak var right_Button: UIButton!      //右边按钮
    
    @IBOutlet weak var left_Button: UIButton!       //左边按钮
    
    @IBOutlet weak var numAndPrice: UILabel!        //商品数量,实付款,运费
    
    @IBOutlet weak var allPriceLabel: UILabel!      //总价
    
    @IBOutlet weak var LineView: UIView!
    
    @IBOutlet weak var YJYL_Label: UILabel!
    var item:TheOrderListModel?{
        didSet{
            if let model = item{
                self.YJYL_Label.text = "(预计盈利:\((model.bdprice - model.orderamount - model.paycoupon).getPriceStr()))"
                self.numAndPrice.text = "共\(model.totalnumber)件商品，实付款："
//                self.numAndPrice.text = "共\(model.totalnumber)件商品，实付款："
                self.allPriceLabel.text = (model.orderamount - model.paycoupon).getPriceStr()
                
                if model.orderstatus == "0"          //待付款状态
                {
                    setStatusButton(button: self.right_Button, title: "立即付款", titleColor: UIColor.white, borderColor: UIColor.clear,hidden: false,backColor: UIColor(hex: "e31436"))
                    
                    
                    setStatusButton(button: self.left_Button, title: "取消订单", titleColor: UIColor(hex: "666666"), borderColor: UIColor(hex: "999999"),hidden: false,backColor: UIColor.white)
                    
                    
                }
                else if model.orderstatus == "7" || model.orderstatus == "8" || model.orderstatus == "9" || model.orderstatus == "10"                       //已关闭状态
                {
                    self.left_Button.isHidden = true
                    setStatusButton(button: self.right_Button, title: "删除订单", titleColor: UIColor(hex: "666666"), borderColor: UIColor(hex: "999999"),hidden: false,backColor: UIColor.white)
                    
                }
                else if model.orderstatus == "5" ||  model.orderstatus == "6"      //待评价状态/已完成状态
                {
                    if model.isevaluate == "0"{
                        
                        self.left_Button.isHidden = false
                        setStatusButton(button: self.left_Button, title: "查看物流", titleColor: UIColor(hex: "666666"), borderColor: UIColor(hex: "999999"),hidden: false,backColor: UIColor.white)
                        setStatusButton(button: self.right_Button, title: "评价", titleColor: UIColor(hex: "e31436"), borderColor: UIColor(hex: "e31436"),hidden: false,backColor: UIColor.white)
                        
                    }else{
                        
                        self.left_Button.isHidden = true
                        setStatusButton(button: self.right_Button, title: "查看物流", titleColor: UIColor(hex: "666666"), borderColor: UIColor(hex: "999999"),hidden: false,backColor: UIColor.white)
                        
                    }
                }
                else if model.orderstatus == "2" ||  model.orderstatus == "1"  //待发货状态
                {
                    self.left_Button.isHidden = true
                    self.right_Button.isHidden = true
                }
                else if model.orderstatus == "3"     //部分发货
                {
                    self.left_Button.isHidden = true
                    self.setStatusButton(button: self.right_Button, title: "查看物流", titleColor: UIColor(hex:"666666"), borderColor: UIColor(hex: "999999"), hidden: false, backColor: UIColor.white)
                    
                }
                else if model.orderstatus == "4"     //全部发货
                {
                    setStatusButton(button: self.right_Button, title: "确认收货", titleColor: UIColor.white, borderColor: UIColor.clear,hidden: false,backColor: UIColor(hex: "e31436"))
                    setStatusButton(button: self.left_Button, title: "查看物流", titleColor: UIColor(hex: "666666"), borderColor: UIColor(hex: "999999"),hidden: false,backColor: UIColor.white)

                }
            }
        }
    }
    //处理状态按钮
    func setStatusButton(button:UIButton,title:String,titleColor:UIColor,borderColor:UIColor?,hidden:Bool,backColor:UIColor?){
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 3
        button.layer.borderWidth = 1
        
        if let NewborderColor = borderColor{
            
            button.layer.borderColor = NewborderColor.cgColor
        }

        button.setTitle(title, for: .normal)
        button.setTitleColor(titleColor, for: .normal)
        
        if let backGroundColor = backColor{
            
            button.backgroundColor = backGroundColor
        }
        button.isHidden = hidden
    }
    

    override func awakeFromNib() {
        super.awakeFromNib()
        LineView.backgroundColor = Theme.v.separate_Line
        numAndPrice.normal_fontSize(13)
        allPriceLabel.normal_fontSize(13)
        left_Button.titleLabel?.normal_fontSize(14)
        right_Button.titleLabel?.normal_fontSize(14)
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
